package com.atguigu.controller;


import com.alibaba.fastjson.JSONObject;
import com.atguigu.cache.ShopCache;
import com.atguigu.entity.*;
import com.atguigu.result.RetVal;
import com.atguigu.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.aspectj.lang.annotation.Around;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 一级分类表 前端控制器
 * </p>
 *
 * @author GuoJH
 * @since 2021-08-21
 */
@RestController
@RequestMapping("/product")
//@CrossOrigin
public class CategoryController {
    @Autowired
    private BaseCategory1Service baseCategory1Service;
    @Autowired
    private BaseCategory2Service baseCategory2Service;
    @Autowired
    private BaseCategory3Service baseCategory3Service;
    @Autowired
    private BaseCategoryViewService categoryViewService;

    //获取一级分类
    @GetMapping("/getCategory1")
    public RetVal getCategory1(){
        List<BaseCategory1> category1List = baseCategory1Service.list(null);
        return RetVal.ok(category1List);
    }
    //获取二级分类
    @GetMapping("/getCategory2/{category1Id}")
    public RetVal getCategory2(@PathVariable Long category1Id){
        QueryWrapper<BaseCategory2> wrapper = new QueryWrapper<>();
        wrapper.eq("category1_id",category1Id);
        List<BaseCategory2> category2List = baseCategory2Service.list(wrapper);
        return RetVal.ok(category2List);
    }
    //获取三级分类
    @GetMapping("/getCategory3/{category2Id}")
    public RetVal getCategory3(@PathVariable Long category2Id){
        QueryWrapper<BaseCategory3> wrapper = new QueryWrapper<>();
        wrapper.eq("category2_id",category2Id);
        List<BaseCategory3> category3List = baseCategory3Service.list(wrapper);
        return RetVal.ok(category3List);
    }
    //获取商品首页的分类信息
    @GetMapping("/getIndexCategoryInfo")
    public RetVal getIndexCategoryInfo(){
        List<JSONObject> categoryInfo = categoryViewService.getIndexCategoryInfo();
        return RetVal.ok(categoryInfo);
    }



}

